package BinaryTree;
/*
* 判断是否为对称二叉树
* 递归判断左右=右左,左左=右右
*
* */
public class Offer28isSymmetric {
    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        return dfs(root,root);
    }

    private boolean dfs(TreeNode r1, TreeNode r2) {
        if(r1==null && r2==null){
            return true;
        }
        if(r1==null || r2==null){
            return false;
        }
        if(r1.val!=r2.val){
            return false;
        }
        boolean l=dfs(r1.left,r2.right);
        boolean r=dfs(r1.right,r2.left);
        return l&&r;
    }
}
